import os
import time
import copy

import cv2
import numpy as np

from utils import img_util 
from collections import Iterable


algo_id = 10


def draw_box_by_data_trt(boxes, scores, label_id, label_dict, img, device):
    #boxes, scores, label_id = np.squeeze(boxes.numpy()), np.squeeze(scores.numpy()), np.squeeze(label_id.numpy())
    #boxes, scores, label_id = list(boxes.numpy()), list(scores.numpy()), list(label_id.numpy())
    print(type(boxes), type(scores), type(label_id))
    print(boxes, scores, label_id)
    print(isinstance(boxes, Iterable), isinstance(scores, Iterable), isinstance(label_id, Iterable))
    save = False
    #list_a = zip(boxes, scores, label_id)
    #print(list_a)

    for (box, score, idx) in zip(boxes.tolist(), scores.tolist(), label_id.tolist()):
        c1, c2 = (int(box[0]), int(box[1])), (int(box[2]), int(box[3]))
        #idx = int(float(idx))
        #print(box, score, idx)
        label = label_dict[idx]
        if score > 0.65 and label == 'call':
            cv2.rectangle(img, c1, c2, (0, 0, 255), thickness=4)
            save = True

    cv2.waitKey(1)
    # 保存图片到指定路径
    if save:
        ori_img = copy.deepcopy(img)
        img_util.save_image(img, device, algo_id, ori_img)

    return img
